package com.family.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.family.gmall.common.result.Result;
import com.family.gmall.model.product.entity.BaseTrademark;
import com.family.gmall.product.service.BaseTrademarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Auther: family
 * @Date: 2023/7/11 09:30
 * @Description:
 */
@Api(tags = "品牌接口")
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Resource
    private BaseTrademarkService baseTrademarkService;

    @ApiOperation("获取品牌分页列表")
    @GetMapping("/{page}/{limit}")
    public Result index(@PathVariable Long page, @PathVariable Long limit) {
        Page<BaseTrademark> pageParam = new Page<>(page, limit);
        return Result.ok(baseTrademarkService.getPage(pageParam));
    }

    @ApiOperation("根据Id获取品牌")
    @ApiImplicitParam(name = "品牌Id", value = "id", required = true)
    @GetMapping("/get/{id}")
    public Result get(@PathVariable String id) {
        return Result.ok(baseTrademarkService.getById(id));
    }

    @ApiOperation("获取品牌属性")
    @GetMapping("/getTrademarkList")
    public Result getTrademarkList() {
        return Result.ok(baseTrademarkService.list(null));
    }

    @ApiOperation("添加品牌")
    @ApiImplicitParam(name = "baseTrademark", value = "baseTrademark", required = true)
    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("修改品牌")
    @ApiImplicitParam(name = "baseTrademark", value = "baseTrademark", required = true)
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

}
